<template>
  <div class="app-container">
    <el-form :model="queryParams" ref="queryForm" size="mini" label-width="68px">
      <el-row :gutter="20">
        <el-col :span="4">
          <el-form-item label="项目区域" prop="projectRegion">
            <el-select v-model="queryParams.projectRegion" placeholder="请选择" clearable
              @keyup.enter.native="handleQuery">
              <el-option v-for="dict in dict.type.cld_project_region" :key="dict.value" :label="dict.label"
                :value="parseInt(dict.value)"></el-option>
            </el-select>
          </el-form-item>
        </el-col>
        <el-col :span="4">
          <el-form-item label="项目名称" prop="projectName">
            <el-input v-model="queryParams.projectName" placeholder="请输入" clearable @keyup.enter.native="handleQuery" />
          </el-form-item>
        </el-col>
        <el-col :span="4">
          <el-form-item label="资产名称" prop="assetsName">
            <el-input v-model="queryParams.assetsName" placeholder="请输入" clearable @keyup.enter.native="handleQuery" />
          </el-form-item>
        </el-col>
        <el-col :span="4">
          <el-form-item label="资产类型" prop="assetsType">
            <el-select v-model="queryParams.assetsType" placeholder="请选择" clearable @keyup.enter.native="handleQuery">
              <el-option v-for="dict in dict.type.cld_assets_type" :key="dict.value" :label="dict.label"
                :value="parseInt(dict.value)"></el-option>
            </el-select>
          </el-form-item>
        </el-col>
        <el-col :span="4">
          <el-form-item label="资产状态" prop="recordStatus">
            <el-select v-model="queryParams.recordStatus" placeholder="请选择" clearable @keyup.enter.native="handleQuery">
              <el-option v-for="dict in recordStatusOptions" :key="dict.value" :label="dict.label"
                :value="parseInt(dict.value)"></el-option>
            </el-select>
          </el-form-item>
        </el-col>
        <el-col :span="4">
          <el-form-item label-width="10px">
            <el-button type="primary" icon="el-icon-search" size="mini" @click="handleQuery">搜索</el-button>
            <el-button icon="el-icon-refresh" size="mini" @click="resetQuery">重置</el-button>
          </el-form-item>
        </el-col>
      </el-row>
    </el-form>
    <el-table v-loading="loading" :data="assetsList" @selection-change="handleSelectionChange" border>
      <el-table-column v-if="isMultiple" type="selection" width="55" align="center" :reserve-selection="true"/>
      <el-table-column label="项目区域" align="center" prop="projectRegion">
        <template slot-scope="scope">
          <dict-tag :options="dict.type.cld_project_region" :value="scope.row.projectRegion" />
        </template>
      </el-table-column>
      <el-table-column label="项目名称" align="center" prop="projectName" />
      <el-table-column label="资产名称" align="center" prop="assetsName" />
      <el-table-column label="资产类型" align="center" prop="assetsType">
        <template slot-scope="scope">
          <dict-tag :options="dict.type.cld_assets_type" :value="scope.row.assetsType" />
        </template>
      </el-table-column>
      <el-table-column label="资产型号" align="center" prop="assetsModel" />
      <el-table-column label="资产ID" align="center" prop="assetsIdCard" />
      <el-table-column label="资产状态" align="center" prop="recordStatus">
        <template slot-scope="scope">
          <dict-tag :options="recordStatusOptions" :value="parseInt(scope.row.recordStatus)" />
        </template>
      </el-table-column>
      <el-table-column v-if="!isMultiple" label="操作" align="center" class-name="small-padding fixed-width">
        <template slot-scope="scope">
          <el-button size="mini" type="text" @click="handleSelected(scope.row)">选择</el-button>
        </template>
      </el-table-column>
    </el-table>
    <pagination v-show="total > 0" :total="total" :page.sync="queryParams.pageNum" :limit.sync="queryParams.pageSize"
      @pagination="getList" />
  </div>
</template>

<script>
import { listRecord } from "@/api/cld/record";
import { recordStatusOptions } from '@/assets/staticDict'
export default {
  name: "selectedAssets",
  dicts: ['cld_assets_type', 'cld_project_region'],
  props: {
    projectId: {
      type: Number
    },
    notAssetsId: {
      type: Array
    },
    recordStatusArr: {
      type: String
    },
    recordStatus: {
      type: Number
    },
    isMultiple: {
      type: Boolean,
      default: false
    },
    notAssetsIds: {
      type: Array
    }
  },
  data() {
    return {
      // 遮罩层
      loading: true,
      total: 0,
      // 项目岗位
      assetsList: [],
      queryParams: {
        pageNum: 1,
        pageSize: 10,
        projectRegion: null,
        projectName: null,
        assetsName: null,
        assetsType: null,
        isNewUpdate: 1,
        recordStatus: this.recordStatus,
        recordStatusArr: this.recordStatusArr,
        params: {
          notAssetsIds: this.notAssetsIds
        }
      },
      // 资产状态
      recordStatusOptions: recordStatusOptions,
    };
  },
  created() {
    this.getList();
  },
  methods: {
    /** 查询资产信息列表 */
    getList() {
      this.loading = true;
      listRecord(this.queryParams).then(response => {
        this.assetsList = response.rows;
        this.total = response.total;
        this.loading = false;
      });
    },
    /** 搜索按钮操作 */
    handleQuery() {
      this.queryParams.pageNum = 1;
      this.getList();
    },
    /** 重置按钮操作 */
    resetQuery() {
      this.resetForm("queryForm");
      this.handleQuery();
    },
    // 单选资产
    handleSelected(e) {
      this.$emit('change', e);
    },
    // 多选框选中数据
    handleSelectionChange(selection) {
      this.$emit('change', selection);
    },
  }
};
</script>
